﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace MDS
{
    public class FutureExchange : EnumBase<char>
    {

        private FutureExchange(char id) :base(id){ }
        private static Dictionary<char, FutureExchange> _allExchanges;

        static FutureExchange()
        {

            JinRong = new FutureExchange('F');
            Shanghai = new FutureExchange('S');
            Dalian = new FutureExchange('D');
            Zhengzhou = new FutureExchange('Z');

            _allExchanges = new Dictionary<char, FutureExchange>();
            _allExchanges.Add(JinRong._value, JinRong);
            _allExchanges.Add(Shanghai._value, Shanghai);
            _allExchanges.Add(Dalian._value, Dalian);
            _allExchanges.Add(Zhengzhou._value, Zhengzhou);

        }

        public static implicit operator FutureExchange(char exchId)
        {
            FutureExchange rtn;
            TryParse(exchId, out rtn);
            return rtn;
        }


        public static bool TryParse(char exchId, out FutureExchange exchange)
        {
            if (_allExchanges.ContainsKey(exchId))
            {
                exchange = _allExchanges[exchId];
                return true;
            }
            else
            {
                exchange = default(FutureExchange);
                return false;
            }
        }
        public static bool TryParse(string exchIdStr, out FutureExchange exchange)
        {
            if (!string.IsNullOrEmpty(exchIdStr))
            {
                char exchId = exchIdStr[0];
                return TryParse(exchId, out exchange);
            }
            else
            {
                exchange = default(FutureExchange);
                return false;
            }

        }
        public static FutureExchange JinRong { get; private set; }
        public static FutureExchange Shanghai { get; private set; }
        public static FutureExchange Dalian { get; private set; }
        public static FutureExchange Zhengzhou { get; private set; }

    }
}
